package com.xyazm.address.api;

import com.xyazm.address.domain.dto.AddressDTO;
import com.xyazm.address.domain.param.QueryAddressParam;
import com.xyazm.address.exception.AddressBizException;
import com.xyazm.address.service.IAddressService;
import com.xyazm.common.core.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 地址服务对外暴露接口
 * @author xuyou
 * @date 2022年06月04日 22:30
 */
@Slf4j
@DubboService(version = "1.0.0",interfaceClass = IAddressApi.class)
public class AddressApi implements IAddressApi {

    @Autowired
    private IAddressService addressService;

    @Override
    public JsonResult<AddressDTO> getAddress(QueryAddressParam param) {
        try {
            AddressDTO address = addressService.getAddress(param);
            return JsonResult.buildSuccess(address);
        } catch (AddressBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
